<template>
    <div>
        <el-row>
            <el-col :span="24">
                <div style="min-height: 50px;background:#f7f7f7;line-height:50px;padding:0px 20px;color:#12bdce">
                    {{ $t("message.new_add") }}
                </div>
            </el-col>
        </el-row>
        <div style="padding-top:10px;padding:15px 0 30px 30px;">
            <el-card>
                <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px">
                    <el-row>
                        <el-col :span="8">
                            <el-form-item label="标题" prop="title">
                                <el-input v-model="ruleForm.title"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-form-item label="关键字" prop="keywords">
                                <el-input v-model="ruleForm.keywords"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24">
                            <el-form-item label="新闻描述">
                                <el-input type="textarea" v-model="ruleForm.description"
                                          :autosize="{ minRows: 2, maxRows: 4}"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-form-item label="图片">
                                <el-upload
                                        action="//jsonplaceholder.typicode.com/posts/"
                                        type="drag"
                                        :thumbnail-mode="true"
                                >
                                    <i class="el-icon-upload"></i>
                                    <div class="el-dragger__text">将图片拖到此处，或<em>点击上传</em></div>
                                    <div class="el-upload__tip" slot="tip">只能上传jpg/png文件，且不超过500kb</div>
                                </el-upload>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24">
                            <el-form-item label="新闻内容">
                                <el-input type="textarea" v-model="ruleForm.message"
                                          :autosize="{ minRows: 4, maxRows: 8}"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-form-item label="地址" prop="address">
                                <el-select v-model="ruleForm.address" placeholder="请选择省份">
                                    <el-option label="上海" value="shanghai"></el-option>
                                    <el-option label="河南" value="henan"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-form-item label="日期" required>
                                <el-form-item prop="date">
                                    <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.date"
                                                    style="width: 100%;"></el-date-picker>
                                </el-form-item>

                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-form-item>
                        <el-button type="primary" @click="handleSubmit">立即创建</el-button>
                        <el-button @click="handleReset">重置</el-button>
                    </el-form-item>
                </el-form>
            </el-card>
        </div>
    </div>
</template>
<script>
    export default {
        data() {
            return {
                ruleForm: {
                    title: '',
                    address: '',
                    date: '',
                    keywords: '',
                    description: '',
                    img: '',
                    message: ''
                },
                rules: {
                    title: [
                        {required: true, message: '请输入标题 ', trigger: 'blur'},
                    ],
                    address: [
                        {required: true, message: '请选择省份', trigger: 'blur'}
                    ],
                    date: [
                        {type: 'date', required: true, message: '请选择日期', trigger: 'blur'}
                    ]
                }
            }
        },
        methods: {
            handleReset() {
                this.$refs.ruleForm.resetFields();
            },
            handleSubmit(ev) {
                this.$refs.ruleForm.validate((valid) => {
                    if (valid) {
                        window.router.push({path: "/new/list/"});
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            }
        }
    }
</script>